package org.jeecg.modules.app.pay.service.impl;

import org.jeecg.common.util.DateUtils;
import org.jeecg.modules.app.pay.service.PayService;
import org.jeecg.modules.power.order.entity.YlMemberOrder;
import org.jeecg.modules.power.order.service.IYlMemberOrderService;
import org.jeecg.modules.power.user.entity.YlUser;
import org.jeecg.modules.power.user.service.IYlUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @BelongsProject: jeecg-boot-parent 回调业务层
 * @BelongsPackage: org.jeecg.modules.app.pay.service.impl
 * @Author: mi
 * @CreateTime: 2024-07-13 16:24
 * @Description:
 */
@Service
public class PayServiceImpl implements PayService {






    @Autowired
    private IYlMemberOrderService ylMemberOrderService;//会员订单表


    @Autowired
    private IYlUserService ylUserService;//用户表

    /**
     * 统一回调 会员充值订单
     * @param ylMemberOrder
     */
    @Override
    public void callbackMemberOrder(YlMemberOrder ylMemberOrder) {
        ylMemberOrderService.updateById(ylMemberOrder);//修改会员数据
        //修改用户数据
        YlUser ylUser= new YlUser();
        ylUser.setId(ylMemberOrder.getUserId());
        ylUser.setMemberId(ylMemberOrder.getMemberId());
        ylUser.setMemberOrderId(ylMemberOrder.getId());//订单id
        //计算 当前时间 加月
        ylUser.setIsMember(1);//是会员  是否是会员0否1是
        ylUser.setBeginTime(ylMemberOrder.getPayTime());
        ylUser.setEndTime(DateUtils.addMonthToDate(ylMemberOrder.getPayTime(),ylMemberOrder.getMonth()));//会员结束日期
        ylUserService.updateById(ylUser);
    }
}
